#include <bits/stdc++.h>
using namespace std;

class comp{
public:
	int left;
	int right;
	bool operator<(comp r){
		if(this->right<r.right)return true;
		if(this->right==r.right&&this->left<r.left)return true;
		return false;
	}
};

int main(void){
	vector<comp> a;
	comp temp;
	int n;
	cin>>n;
	for(int i=0;i<n;i++){
		cin>>temp.left>>temp.right;
		a.push_back(temp);
	}
	sort(a.begin(),a.end());
	int sign=0,sum=0;
	for(int i=0;i<n;i++){
		if(a[i].left>=sign){
			sum++;
			sign=a[i].right;
		}
	}
	cout<<sum;
	return 0;
}
